package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

import com.xcity.db.entity.Financial;
import com.xcity.db.entity.Player;
import com.xcity.game.financial.FinancialTemplate;

@PomeloMessage(type = Message.Type.RESPONSE)
public class FinancialListResponse extends Response {
	
	private List<Product> financialProducts;
	
	public static class Product {
		private int financialId; // 理财产品id
		private String name; // 理财产品名
		private int yieldRate; // 收益率
		private long total; // 总额
		private long minimum; // 最小投资额度
		private int investmentPeriod; // 周期
		private long invested; // 已投金额
		private byte leftNum; // 剩余可投份数
		public int getFinancialId() {
			return financialId;
		}
		public void setFinancialId(int financialId) {
			this.financialId = financialId;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getYieldRate() {
			return yieldRate;
		}
		public void setYieldRate(int yieldRate) {
			this.yieldRate = yieldRate;
		}
		public long getTotal() {
			return total;
		}
		public void setTotal(long total) {
			this.total = total;
		}
		public long getMinimum() {
			return minimum;
		}
		public void setMinimum(long minimum) {
			this.minimum = minimum;
		}
		public int getInvestmentPeriod() {
			return investmentPeriod;
		}
		public void setInvestmentPeriod(int investmentPeriod) {
			this.investmentPeriod = investmentPeriod;
		}
		public long getInvested() {
			return invested;
		}
		public void setInvested(long invested) {
			this.invested = invested;
		}
		public byte getLeftNum() {
			return leftNum;
		}
		public void setLeftNum(byte leftNum) {
			this.leftNum = leftNum;
		}
	}
	
	public FinancialListResponse(int serial, Player player, List<Financial> srcs) {
		super(serial);
		int size = srcs.size();
		List<Product> products = new ArrayList<Product>(size);
		for (int i = 0; i < size; i++) {
			Financial src = srcs.get(i);
			FinancialTemplate template = src.getTemplate();
			Product p = new Product();
			p.financialId = src.getFinancialId();
			p.name = template.getName();
			p.yieldRate = template.getRate();
			p.total = template.getTotal();
			p.minimum = template.getMin();
			p.investmentPeriod = template.getPeriod();
			p.invested = src.getMoney() + template.getMin() > template.getTotal() ? template.getTotal() : src.getMoney();
			p.leftNum = (byte) (template.getLimit() - player.getFinancials().count(p.financialId));
			products.add(p);
		}
		financialProducts = products;
	}

	public List<Product> getFinancialProducts() {
		return financialProducts;
	}

	public void setFinancialProducts(List<Product> financialProducts) {
		this.financialProducts = financialProducts;
	}
	
}
